package com.etoak.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class OrderQueueConfig {
    public static final String EXCHANGE = "amqp.order";

    public static final String QUEUE = "order";

    public static final String KEY = "order";

    @Bean
    public CustomExchange orderExchange(){
        Map<String,Object> map = new HashMap<>();
        map.put("x-delayed-type","direct");
        return new CustomExchange(EXCHANGE,"x-delayed-message",true,false,map);
    }

    @Bean
    public Queue orderQueue(){
        return new Queue(QUEUE);
    }

    @Bean
    public Binding orderBinding(){
        return BindingBuilder.bind(orderQueue()).to(orderExchange()).with(KEY).noargs();
    }
}
